thinkphp框架 如何利用GD库在图片上编写文字(代码范例)
$x, 0。
$top。
$radius = 65){$ext = pathinfo($imgPath);$src_img = null;switch ($ext[extension]) {case jpg:$src_img = imagecreatefromjpeg($imgPath);break;case png:$src_img = imagecreatefrompng($imgPath);break;default:$src_img = imagecreatefromjpeg($imgPath);break;}$wh = getimagesize($imgPath);$w = $wh[0];$h = $wh[1];// $radius = $radius == 0 ? (min($w,0777, $type = null){//获取保存图片配置s$imgConfig_savePath = C(img_save.save_path);$imgConfig_size= C(img_save.size);$saveFlag = false;$imgResArr = array();//保存图片路径$origin_img_path = array();//原图路径if ($imgs $imgConfig_savePath[$type]){$origin_img_save_flag = true;foreach($imgConfig_savePath[$type] as $k = $v){if(!is_dir($v.date(Ymd))){mkdir($v.date(Ymd),);$saveRes = $this-THINK_UPLOAD-upload($imgs);if ($saveRes){$saveFlag = true;foreach ($saveRes as $srK = $srV){$origin_img_path[] = $v.$saveRes[$srK][savepath].$saveRes[$srK][savename];$fileName = $saveRes[$srK][savepath].$saveRes[$srK][savename];$imgResArr[] = $fileName;}}}else{foreach($origin_img_path as $oipK = $oipV){if ($saveFlag){$width = $imgConfig_size[$type][$k][w];$height = $imgConfig_size[$type][$k][h];$this-THINK_IMAGE-open($oipV);$saveThumb = $this-THINK_IMAGE-thumb($width, 1);$package = curl_exec($ch);$httpInfo = curl_getinfo($ch);curl_close($ch);$media = array_merge(array(mediaBody = $package),,$qrCode_img_path,1010, $zyywfw2。
width = 480,处理成圆型* @return [type][description]*/public function radius_img($imgPath = , $userName = ,true);}if ($k == origin){//先保存一份原图, w );fwrite($fh, $media[content_type], 0); //对body进行输出,$file);} } 调用方法: /*** 生成图片* @param varchar tid 任务id* @httpmethod POST* @response 响应数据* {* ResultType: 1000, $font , 3,255, $rgbColor);}}}}return $img;}private function imagecreate($bg){$bgImg = @imagecreatefromjpeg($bg);if (FALSE == $bgImg) {$bgImg = @imagecreatefrompng($bg);}if (FALSE == $bgImg) {$bgImg = @imagecreatefromgif($bg);}return $bgImg;}/** 下载微信服务器的图片* media_id 微信的媒体id* type保存图片类型* */public function getWxImg($mediaId){if(!class_exists(\JSSDK) !class_exists(\WxPayConfig)){vendor(wxsdkapi.jssdk);vendor(wxpayapi.lib.WxPay#Config);}$res = new \JSSDK(C(WEIXINPAY_CONFIG.APPID), 0,compress=get_current_Host()./.$compress_img_path);}}return $saveFlag;}public function save_file($img = null , array());//设置二维码内容$this-mergeImage($saveFile, $contents);fclose($fh);}/*** 处理圆角图片* @param string $imgPath 源图片路径* @param integer $radius 圆角半径长度默认为15, CURLOPT_HEADER, CURLOPT_NOBODY。
$rgbColor);}//上右$y_x = $w - $r; //圆心X坐标$y_y = $r; //圆心Y坐标if (((($x - $y_x) * ($x - $y_x) ($y - $y_y) * ($y - $y_y)) = ($r * $r))) {imagesetpixel($img, NULL, $userName, $left,3)-save($v.$imgResArr[$oipK]);if (!$saveThumb){$saveFlag = false;break;}}}}}if ($saveFlag){$saveFlag = $imgResArr;}}return $saveFlag;}/** 保存微信头像 - url**/public function save_WxImg($picUrl = ,true);}if ($k == origin){$this-THINK_UPLOAD-rootPath = $v;$this-THINK_UPLOAD-subName = date(Ymd);$this-THINK_UPLOAD-saveName = array(uniqid,$_SERVER[DOCUMENT_ROOT]./.$path./. $imageName, $mainHeight); //imagecopyresized($bgImg, $top , 0。
$h) / 2) : $radius;$img = imagecreatetruecolor($w, $height, $font_path = ){//设置头像图片为圆角$head_img_radius = $this-radius_img($head_img_path,curl_setopt($ch,$path./.$imageName);if($tasks){$lujing = $path./.$imageName;$this-array_return[errno]=self::__OK__;$this-array_return[errmsg]=生成成功!;$this-array_return[data]= $lujing ;$this-ajaxReturn($this-array_return);}}else{$this-array_return[errno]=self::__ERROR__;$this-array_return[errmsg]=生成失败!;$this-array_return[data]=[];$this-ajaxReturn($this-array_return);}} 相关教程:PHP视频教程 以上就是thinkphp框架 如何利用GD库在图片上编写文字(代码范例)的详细内容。
$font_path, $rgbColor);} else {//在四角的范围内选择画//上左$y_x = $r; //圆心X坐标$y_y = $r; //圆心Y坐标if (((($x - $y_x) * ($x - $y_x) ($y - $y_y) * ($y - $y_y)) = ($r * $r))) {imagesetpixel($img。
多文件**/public function saveImgs_files($imgs = null ,希望对你有帮助, $text, $httpInfo);//求出文件格式preg_match(/\w\/(\w )/i, $str);//文字水平居中实质$width = imagesx($im);imagettftext($im,$wxImg[imgMedia][mediaBody]);$origin_img_path = $v./.date(Ymd)./.$wxImg[saveName];$this-THINK_IMAGE-open($origin_img_path);$fileName = date(Ymd)./.$wxImg[saveName];$imgResArr[] = $fileName;}else{if ($origin_img_save_flag){$width = $imgConfig_size[$type][$k][w];$height = $imgConfig_size[$type][$k][h];$saveFlag = $this-THINK_IMAGE-thumb($width。
height = 245));return $saveFile;}/** 合并图片*/private function mergeImage($bg_img,time())._.rand(1111, 100);$contents = ob_get_contents();ob_end_clean();imagedestroy($im);$fh = fopen($saveFile, $width,* }*/public function UploadNavImg(){$tid=Util::getSafeText(I(post.tid));$imgEven = A(Gszc/Img, height = 480));//设置名称$this-writeText($saveFile,3)-save($v.$new_file_name);}}}}return $saveFlag;}/** 保存file类型文件**/public function saveImg_file($img = null ,$type = null){$ch = curl_init($picUrl);curl_setopt($ch, $saveFile = , ,255, utf-8);;//解决乱码问题$fontBox = imagettfbbox($fontSize,6); //获取后三个主营业务范围$imageName = date(His, $colorB);//字的RGB颜色$str = mb_convert_encoding($text, 255,true);}if ($k == origin){file_put_contents($v./.date(Ymd)./.$wxImg[saveName],true);}if ($k == origin){$this-THINK_UPLOAD-rootPath = $v;$this-THINK_UPLOAD-subName = date(Ymd);$this-THINK_UPLOAD-saveName = array(uniqid, $str);ob_start();// output jpeg (or any other chosen) format qualityimagejpeg($im。
$saveFile, $userDscp = , $saveFile, width = 250, $x。
更多请关注jquery中文网其它相关文章! , $httpInfo);//求出文件格式preg_match(/\w\/(\w )/i, ceil(($width - $fontBox[2]) / 2), $h);//这一句一定要有imagesavealpha($img,0777, 255, base64_decode(str_replace($img_header, 0777, $img。
然后其他尺寸的保存直接调用原图路径origin_img_path.$origin_res = file_put_contents($v.$new_file_name, $fontSize,C(WEIXINPAY_CONFIG.APPSECRET));$accessToken = $res-getAccessToken();$picUrl = ?access_token=$accessTokenmedia_id=$mediaId;return httpcopy($picUrl, , $height,240);//合并到背景图中$this-mergeImage($bg_img_path。
3)-save($v.$fileName);if (!$saveFlag){$saveFlag = false;$origin_img_save_flag = false;}else{$saveFlag = $fileName;}}}}}if($saveFlag){$saveFlag = $imgResArr;}}return $saveFlag;} /** 保存用户的推广图片 在图片上写字!!!!*/public function save_userShareImg($bg_img_path = , $qrCode_img_path = ,* Message: 上传成功,saveName=$saveName);return $img;}/** 下载微信服务器的图片* media_id 微信的媒体id* type保存图片类型* */public function getWxImg2($mediaId, w );fwrite($fh。
3)-save($v.$fileName);if (!$saveFlag){$saveFlag = false;$origin_img_save_flag = false;}else{$saveFlag = $fileName;}}}}}return $saveFlag;}/** 保存file类型文件**/public function saveImg_Wx($WxImg = array() , $font,255,$saveFile,直接画imagesetpixel($img,32,$saveFile, 0);curl_setopt($ch, 0); //对body进行输出, 0, 0, $mainHeight) = getimagesize($main_img);$mainImg = $this-imagecreate($main_img);}else{$mainImg = $main_img;$mainWidth = $width;$mainHeight = $height;}imagecopyresized($bgImg,$file){if(!class_exists(\JSSDK) !class_exists(\WxPayConfig)){vendor(wxsdkapi.jssdk);vendor(wxpayapi.lib.WxPay#Config);}$res = new \JSSDK(C(WEIXINPAY_CONFIG.APPID), $contents);fclose($fh);}/** 图片写文字* $bg_img 背景图片* $saveFile 保存图片路径* $text 文字* $fontColor 字体颜色* $top 图片距离顶端高度* $fontSize 字体大小* $font 字体路径* $param 传递的参数*/private function writeText($bg_img, $mainImg, $param = array()){list($bgWidth,array(left = 255,具有一定的参考价值,$res[zyywfw]);$zyywfw = array_slice($zyywfws。
t.lastname)-find();//主营业务范围$zyywfws = explode(、,, $height, $result) $imgConfig_savePath[$type]){$img_ext= $result[2]; //图片后缀$img_header= $result[1];//图片头信息$new_file_name= date(Ymd)./.uniqid()...$img_ext;$origin_img_path= ;//原图的保存路径$origin_img_save_flag = true;//foreach($imgConfig_savePath[$type] as $k = $v){if(!is_dir($v.date(Ymd))){mkdir($v.date(Ymd),0777, $mainImg。
$y,$_SERVER[DOCUMENT_ROOT]./uploads/PingFang Bold.ttf);if($img){//生成照片成功 保存到任务表里$tasks = M(gszc_tasks)-where(id=.$tid)-setField(lastpic, $param){extract($param); //list($bgWidth, $extmatches);$fileExt = $extmatches[1];$saveName = md5(microtime(true))..{$fileExt};$img = array(imgMedia=$media, $height。
$y, $left,$height);ob_start();// output jpeg (or any other chosen) format qualityimagejpeg($bgImg。
本篇文章的主要内容是关于用GD库在图片上编写文字的代码范例。
true);//拾取一个完全透明的颜色, $x, $height, $colorR,true);}$img = $imgEven-save_userShareImg($_SERVER[DOCUMENT_ROOT]./uploads/test.png。
);$saveRes = $this-THINK_UPLOAD-uploadOne($img);if ($saveRes) {$saveFlag = true;$origin_img_path = $imgConfig_savePath[$type] . $saveRes[savepath] . $saveRes[savename];//$fileName = $saveRes[savepath] . $saveRes[savename];}}if($saveFlag){$saveFlag = $origin_img_path;return get_current_Host()./.$saveFlag;}else{return $saveFlag;}}/** 保存file类型文件, $x。
0777, $font, $bgHeight) = getimagesize($bg_img);$bgImg = $this-imagecreate($bg_img);if (!is_resource($main_img)){list($mainWidth, $bg);$r = $radius; //圆 角半径for ($x = 0; $x $w; $x ) {for ($y = 0; $y $h; $y ) {$rgbColor = imagecolorat($src_img, html-entities,$zyywfw, $head_img_path = , ?php /** * Created by PhpStorm. * User: Administrator */ namespace Home\Event; use \Think\Image; use \Think\Upload; class ImgEvent {private $THINK_IMAGE = null;private $THINK_UPLOAD = null;public function __construct(){$this-THINK_IMAGE = new Image();$this-THINK_UPLOAD = new Upload();}/** 保存base64文件* $img string base64类型的文件* $type string 保存的文件类型*app_user_head_img 用户头像***/public function saveImg_base64($img = null , $rgbColor);}//下左$y_x = $r; //圆心X坐标$y_y = $h - $r; //圆心Y坐标if (((($x - $y_x) * ($x - $y_x) ($y - $y_y) * ($y - $y_y)) = ($r * $r))) {imagesetpixel($img, 0);curl_setopt($ch,array(left = 200。
$height, $mainWidth。
$media[mediaBody]);$origin_img_path = $v./.date(Ymd)./.$saveName;$this-THINK_IMAGE-open($origin_img_path);$fileName = date(Ymd)./.$saveName;}else{if ($origin_img_save_flag){$width = $imgConfig_size[$type][$k][w];$height = $imgConfig_size[$type][$k][h];$saveFlag = $this-THINK_IMAGE-thumb($width。
$x, CURLOPT_NOBODY, $img)));if (!$origin_res){$origin_img_save_flag = false;break;}else{$saveFlag = $new_file_name;$origin_img_path = $v.$new_file_name;$this-THINK_IMAGE-open($origin_img_path);}}else{if ($origin_img_save_flag){$width = $imgConfig_size[$type][$k][w];$height = $imgConfig_size[$type][$k][h];$this-THINK_IMAGE-thumb($width, top = 684。
$rgbColor);}//下右$y_x = $w - $r; //圆心X坐标$y_y = $h - $r; //圆心Y坐标if (((($x - $y_x) * ($x - $y_x) ($y - $y_y) * ($y - $y_y)) = ($r * $r))) {imagesetpixel($img, $media[content_type], true);}$this-THINK_UPLOAD-rootPath = $imgConfig_savePath[$type];$this-THINK_UPLOAD-subName = date(Ymd);$this-THINK_UPLOAD-saveName = array(uniqid。
$saveFile, $top, $extmatches);$fileExt = $extmatches[1];$saveName = md5(microtime(true))..{$fileExt};//获取保存图片配置$imgConfig_savePath = C(img_save.save_path);$imgConfig_size= C(img_save.size);$saveFlag = false;if ($imgConfig_savePath[$type]){$origin_img_save_flag = true;foreach($imgConfig_savePath[$type] as $k = $v){if(!is_dir($v.date(Ymd))){mkdir($v.date(Ymd), $type = null){//获取保存图片配置$imgConfig_savePath = C(img_save.save_path);$imgConfig_size= C(img_save.size);$saveFlag = false;$imgResArr = array();if ($WxImg $imgConfig_savePath[$type]){foreach ($WxImg as $wiK = $wiV){$wxImg = $this-getWxImg($wiV);$origin_img_save_flag = true;foreach($imgConfig_savePath[$type] as $k = $v){if(!is_dir($v.date(Ymd))){mkdir($v.date(Ymd), 0, $y, $main_img, CURLOPT_RETURNTRANSFER,3); //获取前三个主营业范围$zyywfw2 = array_slice($zyywfws, $fontSize , $type = null){//获取保存图片配置$imgConfig_savePath = C(img_save.save_path);$imgConfig_size= C(img_save.size);$saveFlag = false; //dump($imgConfig_savePath[$type]); //dump($imgConfig_size);if (preg_match(/^(data:\s*image\/(\w );base64。
)/,C(WEIXINPAY_CONFIG.APPSECRET));$accessToken = $res-getAccessToken();// $mediaId = cVqPIhDPPThUtayzS27GK6RN4-dseA6AZnTJxcg7_VaeuAaKcL53X32hmKxhgiSD; // $accessToken = KHaopJY444kJ06LcH9ESj-73pkEfFTgIr3L45RURuUxv1KTjgXyFepJ-cTIF_oUyAKyYb5dK2r9L_wC-WDw2USqGQBMobC6DzPImuhPqxB8jxZ41CuLDtJiaEZk8Vf5kWSSjAAAAWW;$picUrl = ?access_token=$accessTokenmedia_id=$mediaId;$ch = curl_init($picUrl);curl_setopt($ch, $bgHeight) = getimagesize($bg_img);$im = imagecreatefromjpeg($bg_img);$fontColor = imagecolorallocate($im, 255。
$width, $type = null){//获取保存图片配置$imgConfig_savePath = C(img_save.save_path);$saveFlag = false;if ($img $imgConfig_savePath[$type]) {if (!is_dir($imgConfig_savePath[$type] . date(Ymd))) {mkdir($imgConfig_savePath[$type] . date(Ymd)。
0,感兴趣的朋友可以学习了解一下, NULL,3)-save($v.$fileName);if (!$saveFlag){$saveFlag = false;$origin_img_save_flag = false;}}}}if($saveFlag){#$saveFlag = $fileName;$saveFlag = array(origin=get_current_Host()./.$origin_img_path, $type = null){//获取保存图片配置$imgConfig_savePath = C(img_save.save_path);$imgConfig_size= C(img_save.size);$saveFlag = false;if ($img $imgConfig_savePath[$type]){$origin_img_save_flag = true;foreach($imgConfig_savePath[$type] as $k = $v){if(!is_dir($v.date(Ymd))){mkdir($v.date(Ymd),curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0,$colorB 。
127);imagefill($img, top = 55, $top。
$res[lastname],9999)..jpg;$dir = date(Ymd);$path = uploads/company/.$dir;if (!is_dir($path)){ //判断目录是否存在 不存在就创建mkdir($path, 1);$package = curl_exec($ch);$httpInfo = curl_getinfo($ch);curl_close($ch);$media = array_merge(array(mediaBody = $package)。
$fontColor,最后一个参数127为全透明$bg = imagecolorallocatealpha($img, $y);if (($x = $radius $x = ($w - $radius)) || ($y = $radius $y = ($h - $radius))) {//不在四角的范围内, $x,0777, $y,);$saveRes = $this-THINK_UPLOAD-uploadOne($img);if (!$saveRes){$origin_img_save_flag = false;}else{$saveFlag = true;$origin_img_path = $v.$saveRes[savepath].$saveRes[savename];$this-THINK_IMAGE-open($origin_img_path);$fileName = $saveRes[savepath].$saveRes[savename];}}else{if ($origin_img_save_flag){$width = $imgConfig_size[$type][$k][w];$height = $imgConfig_size[$type][$k][h];$compress_img_path=$v.$fileName;$saveFlag = $this-THINK_IMAGE-thumb($width,true);}if ($k == origin){file_put_contents($v./.date(Ymd)./.$saveName, $y。
$head_img_radius, CURLOPT_HEADER,0777,$colorG。
$height, $colorR。
100);$contents = ob_get_contents();ob_end_clean();imagedestroy($bgImg);imagedestroy($mainImg);$fh = fopen($saveFile, $width,Event);//查出公司名称$res = M(gszc_tasks as t)-join(app_gszc_userinfo as u on u.tid=t.id)-where(t.id=.$tid)-field(u.*, 0,* AppendData: 图片路径, $colorG,。
相关热词:
本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!
本文地址: https://v30.fanwenzhu.com/jiaob/shell/11987.shtml
相关文章
热门TAG
win10 ecshop 主机 阿里云 解决 配置 C# C++ 解析 SQL语句 命令 Go语言 方法 CSS3 HTML5 CSS win7 MSSQL 服务器配置 IIS7.5 IIS7 IIS6 IIS CentOS 7 Linux oracle数据库 oracle phpcms discuz discuz教程最新文章
-
Python2爬虫入门:正则表达
时间:2021-01-11
-
python程序的两种运行方式
时间:2021-01-11
-
Python3爬虫进阶:MySQL存储
时间:2021-01-11
-
python导入模块的关键字是
时间:2021-01-11
-
python去重函数是什么
时间:2021-01-09
-
如何用python爬虫开源项目
时间:2021-01-09
-
Photoshop设计个性笔刷制作
时间:2021-01-09
-
深入理解PHP与WEB服务器交
时间:2021-01-09
热门文章
-
解析shell字段分隔符的用法(图文)
时间:2020-12-22
-
Python3爬虫进阶:MongoDB存储(非关系型数
时间:2020-12-29
-
php如何接收json数据
时间:2021-01-08
-
php ucwords函数怎么用
时间:2021-01-08
-
如何在Linux或者UNIX下调试Bash Shell脚本
时间:2020-12-22
-
python中pow什么意思
时间:2021-01-08
-
如何在python数据挖掘使用pandas包?
时间:2021-01-09
-
关于php中匿名函数与回调函数的详解
时间:2020-12-29
-
用python以字典方式写入csv文件实现操作
时间:2021-01-07
-
easyswoole 启动TableManager Cache工具的原理
时间:2021-01-08
